﻿using CSharpDay16__WebAPI_.Adapters.Interfaces;
using CSharpDay16__WebAPI_.Controllers;
using CSharpDay16__WebAPI_.Data;
using CSharpDay16__WebAPI_.Data.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CSharpDay16__WebAPI_.Adapters.Adapters
{
    public class SuperpeopleAdapter : ISuperpeopleAdapter
    {
        public List<SuperPerson> GetAllSuperPeople()
        {
            List<SuperPerson> model;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                model = db.SuperPeople.ToList();
            }
            return model;
        }

        public void AddSuperPerson(PostSuperPersonViewModel model)
        {
            SuperPerson person = new SuperPerson();
            person.Description = model.Description;
            person.ImageUrl = model.ImageUrl;
            person.IsEvil = model.IsEvil;
            person.Name = model.Name;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                db.SuperPeople.Add(person);
                db.SaveChanges();
            }
        }
    }
}